package com.community.common.config;

import com.community.common.config.BizException;
import com.community.common.pojo.response.CodeEnum;
import com.community.common.pojo.response.MyResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice(basePackages = "com.community.common.controller")
public class MyExceptionHandler {

    @ExceptionHandler(value = BizException.class)
    public MyResponse handler(BizException e) {
        return MyResponse.fail(e.getMsg());
    }

    @ExceptionHandler(value = Exception.class)
    public MyResponse handler(Exception e) {
        log.error("未知异常：", e);
        return MyResponse.fail(CodeEnum.SERVICE_EXCEPTION);
    }
}